package com.kaishengit.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.User;
import com.kaishengit.service.ProjectService;
import com.kaishengit.service.UserService;


public class AddProjectServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
		@Override
		protected void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			UserService us=new UserService();
			List<User> Userlist=us.findAll();
			
			request.setAttribute("UserList", Userlist);
			request.getRequestDispatcher("/WEB-INF/views/new_project.jsp").forward(request, response);
			
		}
		@Override
		protected void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			
			String name=request.getParameter("name");
			String desc=request.getParameter("desc");
			String manager=request.getParameter("manager");
			String worker=request.getParameter("workers");
			
			ProjectService service=new ProjectService();
			service.save(name,desc,manager,worker);
			
			response.sendRedirect("main.jspx");
		}
}